const FastCGIClient = require('fastcgi-client');

const client = new FastCGIClient({
  host: '127.0.0.1',
  port: 9898 // PHP-FPM默认端口
});

client.on('ready', () => {
  const request = client.request({
    SCRIPT_FILENAME: './src/components/pageFooter/index.php',
    REQUEST_METHOD: 'GET'
  });

  request.on('response', (response) => {
    response.on('data', (data) => {
      console.log(`stdout: ${data}`);
    });

    response.on('end', () => {
      console.log('PHP脚本执行完毕');
    });
  });

  request.on('error', (error) => {
    console.error(`执行错误: ${error}`);
  });

  request.end();
});

client.on('error', (error) => {
  console.error(`客户端错误: ${error}`);
});